package com.shop.shoporder.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.shop.shoporder.mapper.WapGoodsAndSpecMapper;
import com.shop.shoporder.mapper.WapGoodsDetailsMapper;
import com.shop.shoporder.service.WapGoodsAndSpecService;
import com.shop.shoporder.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("wapGoodsAndSpecService")
public class WapGoodsAndSpecServiceImpl implements WapGoodsAndSpecService {

    @Autowired
    WapGoodsAndSpecMapper wapGoodsAndSpecMapper;
    @Autowired
    WapGoodsDetailsMapper wapGoodsDetailsMapper;
    //根据商品专区查询所有商品
    @Override
    public List<IndexGoodsData> selectGoodesAndSpecByzoneId(Map<String,String> map) throws Exception {
        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));

            int pages = 0;
            int limits = 10;
            List<IndexGoodsData> indexGoodsDataList=null;
            if(map.get("page")!=null){
                pages=Integer.parseInt(map.get("page"));
            }
            if(map.get("limit")!=null){
                limits=Integer.parseInt(map.get("limit"));
            }


            PageHelper.startPage(pages, limits);

            indexGoodsDataList=wapGoodsAndSpecMapper.selectIndexGoodsByzoneId(zoneId);

             PageInfo pageInfo = new PageInfo(indexGoodsDataList);

             return pageInfo.getList();

        }else{
            return null;

        }
    }

    /**
     * 根据商品名称搜索
     * @param goodsName
     * @return
     */
    @Override
    public List<SearchGoods> selectGoodsAndSpaceByGoodsName(String goodsName)throws  Exception {
        return wapGoodsAndSpecMapper.selectGoodsAndSpaceByGoodsName(goodsName);
    }



    @Override
    public List<IndexGoodsRankData> selectIndexGoodsByzoneIdAndRankId(Map<String, String> map) throws Exception {
        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));

            List<IndexGoodsRankData>  indexGoodsRankDataList=wapGoodsAndSpecMapper.selectIndexGoodsByzoneIdAndRankId(zoneId);
            if(indexGoodsRankDataList!=null&&indexGoodsRankDataList.size()!=0){
                return indexGoodsRankDataList;
            }else{
            return null;

            }

        }else{
            return null;

        }
    }

    @Override
    public List<IndexGoodsHYToData> selectIndexGoodsByzoneIAndHY(Map<String,String> map) throws Exception {
        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));


            List<IndexGoodsHYToData> indexGoodsHYToDataList=null;

            indexGoodsHYToDataList=wapGoodsAndSpecMapper.selectIndexGoodsByzoneIAndHY(zoneId);
            if(indexGoodsHYToDataList!=null&&indexGoodsHYToDataList.size()!=0){
                return  indexGoodsHYToDataList;
            }else {
                return null;
            }

        }else{
            return null;

        }
    }

    @Override
    public List<IndexGoodsDZToData> selectIndexGoodsByZoneIdAndDZ1(Map<String, String> map) throws Exception {

        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));

            List<IndexGoodsDZToData> indexGoodsDZToDataList=null;


            indexGoodsDZToDataList=wapGoodsAndSpecMapper.selectIndexGoodsByZoneIdAndDZ1(zoneId);

        if(indexGoodsDZToDataList!=null&&indexGoodsDZToDataList.size()!=0) {
            return indexGoodsDZToDataList;
        }else{
            return null;
            }
        }else{
            return null;

        }
    }

    @Override
    public List<IndexGoodsDZToData> selectIndexGoodsByZoneIdAndDZ2(Map<String, String> map) throws Exception {
        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));

            List<IndexGoodsDZToData> indexGoodsDZToDataList=null;


            indexGoodsDZToDataList=wapGoodsAndSpecMapper.selectIndexGoodsByZoneIdAndDZ2(zoneId);

          if(indexGoodsDZToDataList!=null&&indexGoodsDZToDataList.size()!=0){
              return indexGoodsDZToDataList;
          }else{
              return null;
          }



        }else{
            return null;

        }
    }

    @Override
    public List<IndexGoodsDZToData> selectIndexGoodsByZoneIdAndDZ3(Map<String, String> map) throws Exception {
        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));

            List<IndexGoodsDZToData> indexGoodsDZToDataList=null;

            indexGoodsDZToDataList=wapGoodsAndSpecMapper.selectIndexGoodsByZoneIdAndDZ3(zoneId);

            if(indexGoodsDZToDataList!=null&&indexGoodsDZToDataList.size()!=0){
                return indexGoodsDZToDataList;
            }else{
                return null;
            }


        }else{
            return null;

        }
    }

    @Override
    public List<IndexGoodsDZToData> selectIndexGoodsByZoneIdAndDZ4(Map<String, String> map) throws Exception {
        if(map!=null&&map.get("zoneId")!=null){
            int zoneId=Integer.parseInt(map.get("zoneId"));



            List<IndexGoodsDZToData> indexGoodsDZToDataList=null;

            indexGoodsDZToDataList=wapGoodsAndSpecMapper.selectIndexGoodsByZoneIdAndDZ4(zoneId);

            if(indexGoodsDZToDataList!=null&&indexGoodsDZToDataList.size()!=0){
                return indexGoodsDZToDataList;
            }else{
                return null;
            }



        }else{
            return null;

        }
    }

    @Override
    public List<Goods> selectList() {
        return wapGoodsAndSpecMapper.selectList();
    }


    @Override
    public List<IndexGoods> getIndexGoods(int zoneId) {
        if(zoneId==11)
        {
            return wapGoodsAndSpecMapper.getIndexGoods11();
        }
        else {
            return wapGoodsAndSpecMapper.getIndexGoods(zoneId);
        }
    }

    @Override
    public List<IndexGoods> getIndexGoodsAttr() {
        return wapGoodsAndSpecMapper.getIndexGoodsAttr();
    }

    @Override
    public List<IndexGoods> getIndexGoodsShop() {
        return wapGoodsAndSpecMapper.getIndexGoodsShop();
    }


}
